package com.beerandjesus.sportofkings.handicapper.model;

import static com.beerandjesus.sportofkings.handicapper.factory.ResultsTableFactory.*;
import org.apache.commons.lang.StringUtils;

/**
 * Date: Jul 14, 2012
 * Time: 9:08:39 AM
 */
public class MaidenHorseAnalysisResultImpl extends HorseAnalysisResultImpl
        implements MaidenHorseAnalysisResult {

    private String numberOfStarts;
    private String sireWinPercentage;
    private String trainerWinPercentage;
    private String auctionPriceStudFeeRatio;


    public String getNumberOfStarts() {
        return numberOfStarts;
    }

    public void setNumberOfStarts(String numberOfStarts) {
        this.numberOfStarts = numberOfStarts;
    }

    public String getSireWinPercentage() {
        return sireWinPercentage;
    }

    public void setSireWinPercentage(String sireWinPercentage) {
        this.sireWinPercentage = sireWinPercentage;
    }

    public String getTrainerWinPercentage() {
        return trainerWinPercentage;
    }

    public void setTrainerWinPercentage(String trainerWinPercentage) {
        this.trainerWinPercentage = trainerWinPercentage;
    }

    public void addToTable(ResultsTable table) {

        table.putValue(getPostPosition(), getResultType(), STARTS, getNumberOfStarts());
        table.putValue(getPostPosition(), getResultType(), SIRE_TRAINER_WORKOUTS,
                (getSireWinPercentage() == null ? "" : getSireWinPercentage() + " " )
                        + (getTrainerWinPercentage() == null ? "" : getTrainerWinPercentage() + " ") 
                        + concatenateFastWorkouts());
        String speed = "";
        if (!StringUtils.isEmpty(getNumberOfStarts())) {
            try {
                Integer starts = Integer.valueOf(getNumberOfStarts());
                if (starts > 0) {
                    speed = getParSpeedCount() + "par " +
                            getSpeedFigure();
                }
            } catch (NumberFormatException e) {
                // Ignore
            }
        }
        table.putValue(getPostPosition(), getResultType(), SPEED, speed);
        table.putValue(getPostPosition(), getResultType(), NAME, getName());
        String ml = "";
        if (getMorningLine() != null) {
            ml = getMorningLine().toImproperFractionString();
        }
        table.putValue(getPostPosition(), getResultType(), MORNING_LINE, ml);
        table.putValue(getPostPosition(), getResultType(), AUCTION_PRICE_STUD_FEE, getAuctionPriceStudFeeRatio());
        table.putProfiles(getPostPosition(), getResultType(), getProfiles());

    }

    public String getAuctionPriceStudFeeRatio() {
        return auctionPriceStudFeeRatio;
    }

    public void setAuctionPriceStudFeeRatio(String auctionPriceStudFeeRatio) {
        this.auctionPriceStudFeeRatio = auctionPriceStudFeeRatio;
    }
}
